<template>
	<view class="content">
		<view class="hei20"></view>
		<view class="wid90 mar borRad20 coFFF" style="background-color: #035DFF;padding: 45rpx 0;">
			<view class="wid87 mar">
				<view class="foSi40 fowe600">我的奖励金</view>
				<view class="dis disAl disJuB hei60" style="margin-top: 50rpx;">
					<view class="foSi40" style="vertical-align: bottom;">
						<span>¥</span>
						<span class="fowe600 foSi60">{{rewards}}</span>
					</view>
					<view class="dis disAl disJuC foSi30 borRad40 bacFFF" @click="dingyue()"
						style="width: 150rpx;height: 60rpx;color: #035DFF;">去提现</view>
				</view>
				<view class="dis disJuB" style="margin-top: 80rpx;">
					<view class="textCen">
						<view class="foSi40 fowe600">{{count}}</view>
						<view class="foSi25 mar-top10">邀请好友</view>
					</view>
					<view class="textCen">
						<view class="foSi40 fowe600">{{divide_integral}}</view>
						<view class="foSi25 mar-top10">获得积分</view>
					</view>
					<view class="textCen">
						<view class="foSi30" style="vertical-align: bottom;">
							<span>¥</span>
							<span class="fowe600 foSi40">{{divide_money}}</span>
						</view>
						<view class="foSi25 mar-top10">获得奖励</view>
					</view>
				</view>
			</view>
		</view>
		<view class="wid90 mar bacFFF borRad20 " style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);margin-top: 50rpx;">
			<view class="wid87 mar">
				<view class="hei20"></view>
				<view class="fowe600 foSi40 mar-top20">我的好友</view>
				<view class="mar-top40 dis disAl foSi25" style="opacity: 0.8;margin-bottom: 35rpx;">
					<view class="wid33 textCen">好友手机号</view>
					<view class="wid33 textCen">状态</view>
					<view class="wid33 textCen">奖励是否到账</view>
				</view>
				<scroll-view style="max-height: 625rpx;" class="wid100" scroll-y="true" @scrolltolower="lower">
					<block v-for="(item,index) in list" :key="index">
						<view class="dis disAl foSi30 fowe600 mar-bott30">
							<view class="wid33 textCen" style="color: #010101;">{{item.mobile}}</view>
							<view class="wid33 textCen" :style="true?'color: #035DFF;':'color: #FE6522;'">已注册</view>
							<view class="wid33 textCen" :style="item.count != 0?'color: #035DFF;':'color: #FE6522;'">{{item.count != 0?'已到账':'未到账'}}</view>
						</view>
					</block>
				</scroll-view>
				<view style="height: 30rpx;"></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url: this.global.url,
				list: [],
				count: 0,
				divide_money: 0,
				divide_integral: 0,
				rewards: 0,
				wechat_status: 0
			}
		},
		onLoad() {
			this.getList()
		},
		onShow() {},
		methods: {
			getList() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_user_son_list',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.count = result.data.count
							that.divide_money = result.data.divide_money
							that.divide_integral = result.data.divide_integral
							that.rewards = result.data.rewards
							that.list = result.data.list
						}
					}
				})
			},
			getPaymentInfo() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_payment_info',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.wechat_status = result.data.wechat_status
						}
					}
				})
			},
			dingyue() {
				var that = this
				// 要检查的订阅id
				let id = uni.getStorageSync('tzId').withdrawal_success_template
				// 这里是获取下发权限地方，根据官方文档，可以根据  wx.getSetting() 的 withSubscriptions   这个参数获取用户是否打开订阅消息总开关。后面我们需要获取用户是否同意总是同意消息推送。所以这里要给它设置为true 。
				wx.getSetting({
					withSubscriptions: true, //  这里设置为true,下面才会返回mainSwitch
					success: function(res) {
						// 调起授权界面弹窗
						// if (res.subscriptionsSetting.mainSwitch) { // 用户打开了订阅消息总开关
						// 	if (res.subscriptionsSetting.itemSettings !=
						// 		null) { // 用户同意总是保持是否推送消息的选择, 这里表示以后不会再拉起推送消息的授权
						// 		that.tishi()
						// 	} else {
								// 当用户没有点击 ’总是保持以上选择，不再询问‘  按钮。那每次执到这都会拉起授权弹窗
								wx.showModal({
									title: '提示',
									content: '请授权开通服务通知',
									showCancel: true,
									success: function(ress) {
										if (ress.confirm) {
											wx.requestSubscribeMessage({ // 调起消息订阅界面
												tmplIds: [id],
												success(res) {
													console.log('订阅消息 成功 ');
													console.log(res);
													that.tishi()
												},
												fail(er) {
													console.log("订阅消息 失败 ");
													console.log(er);
													that.tishi()
												}
											})
										}
									}
								})
						// 	}
						// } else {
						// 	console.log('订阅消息未开启')
						// 	that.tishi()
						// }
					},
					fail: function(error) {
						console.log(error);
						that.tishi()
					},
				})
			},
			tishi(){
				var that = this
				if(that.rewards <= 0){
					return  uni.showToast({title:'暂无可提现金额',icon:'none',duration: 1000})
				}
				uni.showModal({
				    title: '温馨提示',
				    content: '确认要提现么吗?',
				    success: function (res) {
				        if (res.confirm) {
							that.tixian()
				        } else if (res.cancel) {
				            uni.showToast({
				            	title:'取消提现',
				            	icon:'none',
								duration: 1000
				            })
				        }
				    }
				});
			},
			tixian() {
				var that = this;
				uni.request({
					url: that.global.url + '/api/qianyu_petrol/gasstation_pay_take_money',
					method: "POST",
					header: {
						'site-id': that.global.site_id,//自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						amount: that.rewards,
						type: that.wechat_status
					},
					success(res) {
						let result = res.data
						console.log(result)
						if (result.code == 1) {
							that.getList()
							uni.showToast({
								title:'提现成功',
								icon:'none',
								duration: 1000
							})
						}else{
							uni.showToast({
								title:result.msg,
								icon:'none',
								duration: 1000
							})
						}
					}
				})
			},
			lower(e) {
				if(this.last_page > this.page){
					this.page++
					this.getList()
				}
			},
		}
	}
</script>

<style>
	.content {
		background: #fff;
		height: 100vh;
	}
</style>
